package com.magic.enums;

import com.magic.process.IMeetingEvent;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author magic
 * @version 1.0
 * @date 2022/2/22 14:56
 */
@Slf4j
public enum MeetingEventEnum {
  /**
   * 预定
   */
  RESERVE(IMeetingEvent.ReserveEvent.class, MeetingStatusEnum.PENDING, null),
  /**
   * 审批通过
   */
  AUDIT(IMeetingEvent.AuditEvent.class, MeetingStatusEnum.PENDING, MeetingStatusEnum.AUDIT),
  /**
   * 审批拒绝
   */
  REJECT(IMeetingEvent.RejectEvent.class, MeetingStatusEnum.REJECT, MeetingStatusEnum.AUDIT),
  /**
   * 审批拒绝修改
   */
  MODIFY(IMeetingEvent.ModifyEvent.class, MeetingStatusEnum.AUDIT, MeetingStatusEnum.REJECT),
  /**
   * 更新的修改
   */
  UPDATE(IMeetingEvent.UpdateEvent.class, MeetingStatusEnum.PENDING, MeetingStatusEnum.PENDING),
  /**
   * 正向同步预定
   */
  SYNC_RESERVE(IMeetingEvent.SyncReserveEvent.class, MeetingStatusEnum.PENDING, null),
  /**
   * 正向同步更新
   */
  SYNC_UPDATE(IMeetingEvent.SyncUpdateEvent.class, MeetingStatusEnum.PENDING, MeetingStatusEnum.OPENED),
  /**
   * 取消
   */
  CANCEL(IMeetingEvent.CancelEvent.class, MeetingStatusEnum.CANCEL, MeetingStatusEnum.PENDING,
          MeetingStatusEnum.REJECT),
  /**
   * 开始
   */
  START(IMeetingEvent.StartEvent.class, MeetingStatusEnum.OPENED, MeetingStatusEnum.PENDING),
  /**
   * 延长
   */
  EXTEND(IMeetingEvent.ExtendEvent.class, MeetingStatusEnum.OPENED, MeetingStatusEnum.OPENED),
  /**
   * 结束
   */
  END(IMeetingEvent.EndEvent.class, MeetingStatusEnum.ENDED, MeetingStatusEnum.OPENED),
  /**
   * 会议签到
   */
  CHECK_IN(IMeetingEvent.CheckInEvent.class, null),

  /**
   * 提醒
   */
  NOTICE(IMeetingEvent.NoticeEvent.class, null);

  private static Map<Class<? extends IMeetingEvent>, MeetingEventEnum> eventEnumMap;

  private Class<? extends IMeetingEvent> eventClazz;
  private MeetingStatusEnum target;
  private MeetingStatusEnum[] src;
  MeetingEventEnum(MeetingStatusEnum target, MeetingStatusEnum... src) {
    this(null, target, src);
  }
  MeetingEventEnum(Class<? extends IMeetingEvent> eventClazz, MeetingStatusEnum target, MeetingStatusEnum... src) {
    this.eventClazz = eventClazz;
    this.target = target;
    this.src = src;
    put(eventClazz);
  }
  private void put(Class eventClazz) {
    if (eventEnumMap == null) {
      eventEnumMap = new HashMap(16);
    }
    if (eventClazz != null) {
      eventEnumMap.put(eventClazz, this);
    }
  }
  /**
   * 获取IMeetingEvent接口 对应的事件类型
   *
   * @param eventClazz
   * @return
   */
  public static MeetingEventEnum get(Class<? extends IMeetingEvent> eventClazz) {
    if (eventClazz != null && eventClazz.getInterfaces() != null) {
      return eventEnumMap.get(eventClazz);
    }
    log.warn("未能获取有效的枚举类型 class = {}", eventClazz);
    return null;
  }
}
